// /usr/bin/g++ -std=c++11 -fdiagnostics-color=always -g /home/liuyuelong/workspace/CppLearn/valgrind/main.cpp -o /home/liuyuelong/workspace/CppLearn/valgrind/main

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void test_malloc_error()
{
    char *test = (char *)malloc(32);
}

void test_new_error()
{
    int *test = new int(32);
}

void test_malloc()
{
    char *test = (char *)malloc(32);
    free(test);
    test = NULL;
}

void test_new()
{
    int *test = new int(32);
    delete test;
    test = nullptr;
}

int main()
{
    printf("Hello World!\n");

    for (int i = 0; i < 10; i++)
    {
        test_malloc();
        test_malloc_error();
        test_new();
        test_new_error();
        printf("...\n");
        sleep(1);
    }

    return 0;
}